#!/bin/bash
if [ -f /data/app/iotServer/iotServer.jar ];then
  ulimit -n 65535
  echo ulimit -n 65535 >> /etc/profile
  source /etc/profile
  echo 10000 > /proc/sys/net/core/somaxconn
  echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
  echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
  echo 0 > /proc/sys/net/ipv4/tcp_syncookies
  echo "* soft nofile 65565" >> /etc/security/limits.conf
  echo "* hard nofile 65565" >> /etc/security/limits.conf
  yum -y install epel-release
  yum -y install supervisor wget
  mkdir -p /root/logs/iot
  touch /etc/supervisord.d/iot-server.ini
  cat > /etc/supervisord.d/iot-server.ini << EOF
  [program:iot-server]
  user=root
  command=/usr/local/jdk1.8.0_251/bin/java -jar /data/app/iotServer/iotServer.jar --tcpPort=10011 --httpPort=10012 --webSocketPort=10013
  autostart=true
  autorestart=true
  redirect_stderr=true
  stdout_logfile=/root/logs/iotp/out.log
  stopasgroup=true
  killasgroup=true
EOF
  systemctl enable supervisord
  systemctl restart supervisord
  supervisorctl reload 2>&1 > /dev/null
  supervisorctl start iot-server
  echo "Success"
else
  echo "File '/data/app/iotServer/iotServer.jar' is not found."
fi